package com.richfit.cuba.web.config.db.singleDB;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.alibaba.druid.support.http.StatViewServlet;
import com.alibaba.druid.support.http.WebStatFilter;


@Configuration
public class DruidMonitorConfig {
	
	@Bean
    public ServletRegistrationBean druidServlet() {
        ServletRegistrationBean reg = new ServletRegistrationBean(new StatViewServlet(), "/druid/*");
//        reg.setServlet(new StatViewServlet());
//        reg.addUrlMappings("/druid/*");
        //控制台管理用户
        reg.addInitParameter("loginUsername", "");
        reg.addInitParameter("loginPassword", "");
        // IP白名单
        reg.addInitParameter("allow", "*");
        // IP黑名单(共同存在时，deny优先于allow)
        //reg.addInitParameter("deny", "192.168.1.100");
        //是否能够重置数据 禁用HTML页面上的“Reset All”功能
        reg.addInitParameter("resetEnable", "false");
        reg.addInitParameter("logSlowSql", "true");
        return reg;
    }

    @Bean
    public FilterRegistrationBean filterRegistrationBean() {
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
        filterRegistrationBean.setFilter(new WebStatFilter());
        filterRegistrationBean.addUrlPatterns("/*");
        filterRegistrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*");
        filterRegistrationBean.addInitParameter("profileEnable", "true");
        return filterRegistrationBean;
    }
}
